package com.yxkj.railservicer.bean;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yxkj.railservicer.util.StringUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sunyu on 2017/2/28.
 */

public class QuHuoBean {
    private String first_time;
    private String time;
    private String last_time;
    private String icon;
    private String order;
    //    private int icon;
    private String name;
    private String addressGet;
    private String addressPost;
    private String orderStatus;
    private String orderCancelStatus;
    private String cancelReason;
    private List<SubOrderDetailBean> foodList;
    private String total;
    private String distributionCosts;

    public QuHuoBean() {

    }

    public QuHuoBean(JSONObject obj) {
        this.first_time = obj.getString("updateDate");
        if (obj.getString("aboardTime") == null) {
            this.time = "- -";
        } else {
            this.time = StringUtil.getTime(obj.getString("aboardTime"));
        }
        this.last_time = StringUtil.getTime(obj.getString("latestServiceTime"));
        this.icon = obj.getString("merchantLogoUrl");
        this.order = obj.getString("orderNo");
        this.name = obj.getString("merchantName");
        this.addressGet = obj.getString("fromAddress");
        this.addressPost = obj.getString("deliverAddress");
        this.orderStatus = obj.getString("orderStatus");
        this.orderCancelStatus = obj.getString("orderCancelStatus");
        this.cancelReason = obj.getString("cancelReason");

        foodList = new ArrayList<>();
        JSONArray subs = obj.getJSONArray("subOrders");
        this.distributionCosts = obj.getString("distributionCosts");

        BigDecimal price = new BigDecimal(distributionCosts);
        if (subs != null) {
            JSONObject sub;
            for (int i = 0; i < subs.size(); i++) {
                sub = subs.getJSONObject(i);
                foodList.add(JSONObject.toJavaObject(sub, SubOrderDetailBean.class));
            }
            foodList.add(new SubOrderDetailBean("配送费", 1, price));
        }

        this.total = obj.getString("orderTotalPrice");
    }

    public String getFirst_time() {
        return first_time;
    }

    public void setFirst_time(String first_time) {
        this.first_time = first_time;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getLast_time() {
        return last_time;
    }

    public void setLast_time(String last_time) {
        this.last_time = last_time;
    }

    //    public int getIcon() {
//        return icon;
//    }
//
//    public void setIcon(int icon) {
//        this.icon = icon;
//    }
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddressGet() {
        return addressGet;
    }

    public void setAddressGet(String addressGet) {
        this.addressGet = addressGet;
    }

    public String getAddressPost() {
        return addressPost;
    }

    public void setAddressPost(String addressPost) {
        this.addressPost = addressPost;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    public String getOrderCancelStatus() {
        return orderCancelStatus;
    }

    public void setOrderCancelStatus(String orderCancelStatus) {
        this.orderCancelStatus = orderCancelStatus;
    }

    public String getCancelReason() {
        return cancelReason;
    }

    public void setCancelReason(String cancelReason) {
        this.cancelReason = cancelReason;
    }

    public List<SubOrderDetailBean> getFoodList() {
        return foodList;
    }

    public void setFoodList(List<SubOrderDetailBean> foodList) {
        this.foodList = foodList;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getDistributionCosts() {
        return distributionCosts;
    }

    public void setDistributionCosts(String distributionCosts) {
        this.distributionCosts = distributionCosts;
    }


}
